# 哈希，双O（n^2）
class Solution:
    def equalPairs(self, grid: List[List[int]]) -> int:
        dic = {}
        ans = 0
        n = len(grid)
        # 确定列的组合
        for j in range(n):
            temp = []
            for i in range(n):
                temp.append(grid[i][j])
            dic[j] = temp
        # 行与列对比
        for i in range(n):
            tep = []
            for j in range(n):
                tep.append(grid[i][j])
            for item in dic.values():
                if item == tep:
                    ans += 1

        return ans